using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using Atom.Data.ManagerObjects;
using Atom.Data.BusinessObjects;
using Atom.Data.Base;

namespace Atom.Data.UnitTests
{
	[TestFixture]
    public partial class TPatientInfoTests : UnitTestbase
    {
        [SetUp]
        public void SetUp()
        {
            manager = managerFactory.GetTPatientInfoManager();
            manager.Session.BeginTransaction();
        }

        [TearDown]
        public void TearDown()
        {
            manager.Session.RollbackTransaction();
            manager.Dispose();
        }
        
        protected Atom.Data.ManagerObjects.ITPatientInfoManager manager;
		
		protected Atom.Data.BusinessObjects.TPatientInfo CreateNewTPatientInfo()
		{
			Atom.Data.BusinessObjects.TPatientInfo entity = new Atom.Data.BusinessObjects.TPatientInfo();
			
			// You may need to maually enter this key if there is a constraint violation.
			entity.Id = "Test Test";
			
			entity.Codeno = "T";
			entity.Identityname = "Test Test Tes";
			entity.Spellno = "Test";
			entity.Customno = "Test ";
			entity.Strokeno = "Te";
			entity.Patientname = "Test Test T";
			entity.Sex = "T";
			entity.Birthday = System.DateTime.Now;
			entity.Age = 25;
			entity.Marriagestatus = "Te";
			entity.Nationality = "Test Test ";
			entity.Countysanjak = "Test";
			entity.Identitycard = "Test Test Test Test Test ";
			entity.Address = "Test Test Test Te";
			entity.Casenumber = "Test Te";
			entity.Employment = "Test Test Test";
			entity.Telephone = "Te";
			entity.Mobile = "Tes";
			entity.Unitpostcode = "Test Test Test T";
			entity.Sicktype = "Tes";
			entity.Unittelephone = "Test ";
			entity.Cardid = "Te";
			entity.Medicaresafetyid = "Test";
			entity.Mark = "Test Test Test Test Test Test T";
			entity.Medicaretype = "Test ";
			entity.Workunit = "Test Test ";
			entity.Registeredaddress = "T";
			entity.Nation = "Test T";
			entity.Postalcode = "Test Test Test Test";
			entity.Registeredtele = "Te";
			entity.Accessiontime = System.DateTime.Now;
			entity.Homeplace = "Test Test ";
			entity.Insurer = "Test Test Test Test Test Te";
			entity.Policy = "Test Tes";
			entity.Compactunit = "Test Test Te";
			entity.Ageunit = "T";
			entity.Avoirdupois = 64;
			entity.Pathophysiological = "Test Test ";
			entity.Allergy = "Test Test ";
			
			return entity;
		}
		protected Atom.Data.BusinessObjects.TPatientInfo GetFirstTPatientInfo()
        {
            IList<Atom.Data.BusinessObjects.TPatientInfo> entityList = manager.GetAll(1);
            if (entityList.Count == 0)
                Assert.Fail("All tables must have at least one row for unit tests to succeed.");
            return entityList[0];
        }
		
		[Test]
        public void Create()
        {
            try
            {
				Atom.Data.BusinessObjects.TPatientInfo entity = CreateNewTPatientInfo();
				
                object result = manager.Save(entity);

                Assert.IsNotNull(result);
            }
            catch(Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        [Test]
        public void Read()
        {
            try
            {
                Atom.Data.BusinessObjects.TPatientInfo entityA = CreateNewTPatientInfo();
				manager.Save(entityA);

                Atom.Data.BusinessObjects.TPatientInfo entityB = manager.GetById(entityA.Id);

                Assert.AreEqual(entityA, entityB);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
		[Test]
		public void Update()
        {
            try
            {
                Atom.Data.BusinessObjects.TPatientInfo entityA = GetFirstTPatientInfo();
				
				entityA.Codeno = "Tes";
				
				manager.Update(entityA);

                Atom.Data.BusinessObjects.TPatientInfo entityB = manager.GetById(entityA.Id);

                Assert.AreEqual(entityA.Codeno, entityB.Codeno);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
        [Test]
        public void Delete()
        {
            try
            {
                Atom.Data.BusinessObjects.TPatientInfo entity = GetFirstTPatientInfo();
				
                manager.Delete(entity);

                entity = manager.GetById(entity.Id);
                Assert.IsNull(entity);
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.ToString());
            }
        }
	}
}

